package cn.edu.lingnan.controller;

import cn.edu.lingnan.domain.dto.CreateAccount;
import cn.edu.lingnan.domain.pojo.Result;
import cn.edu.lingnan.domain.vo.AccountVo;
import cn.edu.lingnan.domain.vo.ManageUserVo;
import cn.edu.lingnan.service.TellerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/teller")
@RequiredArgsConstructor




public class TellerController {


    private final TellerService tellerService;

    //查询账户信息
    @GetMapping("/queryAllAccount")
    private Result<List<AccountVo> > queryAllAccount() {
        log.info("查询所有账户信息");
        List<AccountVo> accountVos = tellerService.queryAllAccount();
        return Result.success(accountVos);
        }
   //修改账户状态
    @PutMapping("/updateAccountStatus")
    private Result<String> updateAccountStatus(Integer accountId,String status) {
        log.info("修改账户状态,");
        tellerService.updateAccountStatus(accountId,status);
        return Result.success("修改成功");
    }
    //开户
    @PostMapping("/openAccount")
    private Result<String> openAccount(@RequestBody CreateAccount createAccount) {
        log.info("开户");
        tellerService.openAccount(createAccount);
        return Result.success("开户成功");
    }

    //存款
    @PutMapping("/deposit")
    private Result<String> deposit(Integer accountId,Double balance) {
        log.info("存款");
        tellerService.deposit(accountId,balance);
        return Result.success("存款成功");
    }

    //取款
    @PutMapping("/withdraw")
    private Result<String> withdraw(Integer accountId,Double balance) {
        log.info("取款");
        tellerService.withdraw(accountId,balance);
        return Result.success("取款成功");
    }

    //查询用户信息
    @GetMapping("/queryUserInfo")
    private Result<List<ManageUserVo>> queryUserInfo() {
        log.info("查询用户信息");
        List<ManageUserVo> manageUserVos = tellerService.queryUserInfo();
        return Result.success(manageUserVos);
    }

}
